﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using Eaglight.Extentions;
using ESRI.ArcGIS.Client.Symbols;

namespace Eaglight.Behaviors
{
    public class DrawFreehandBehavior: DrawBehavior
    {
        private Draw draw;

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.Cursor = Cursors.Stylus;
            draw = AssociatedObject.GetDrawObject();
            draw.DrawMode = DrawMode.Freehand;
            draw.LineSymbol = (HotSymbol == null) ? new LineSymbol() : (LineSymbol)HotSymbol;
            draw.DrawComplete += new EventHandler<DrawEventArgs>(draw_DrawComplete);
            draw.Map = AssociatedObject;
            draw.IsEnabled = true;
        }

        protected override void OnDetaching()
        {
            AssociatedObject.Cursor = Cursors.Arrow;
            AssociatedObject.GetDrawObject().IsEnabled = false;
        }

        void draw_DrawComplete(object sender, DrawEventArgs e)
        {
            Graphic g = new Graphic();
            g.Symbol = (Symbol == null) ? new LineSymbol() : (LineSymbol)Symbol;
            g.Geometry = e.Geometry;
            GraphicsLayer.Graphics.Add(g);
        }        
    }
}
